package com.mcptt.config.model;

import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.UserInfo;

import android.os.Parcel;
import android.os.Parcelable;

public class McIdInfo implements Parcelable
{
	public static final String Default_SaInfo = "123456789012";
	private String addrId = null;
	private String pwd = null;

	private String mcpttId = null;
	private String mcvideoId = null;
	private String mcdataId = null;

	private String accessToken = null;

	private String clientId = null;

	private String name = null;

	private String saInfo = Default_SaInfo;

	private int publishRsult = 0;



	public McIdInfo(String addrId,String pwd)
	{
		this.addrId = addrId;
		this.pwd = pwd;
	}

	public void updateMcIdInfo(String addrId,String pwd)
	{
		this.addrId = addrId;
		this.pwd = pwd;
	}
	public void clearPwd()
	{
		this.pwd = "";
	}

	public void updateMcInfo(String mcpttId,String mcvideoId,String mcdataId,String clientId)
	{
		this.mcpttId = mcpttId;
		this.mcvideoId = mcvideoId;
		this.mcdataId = mcdataId;
		this.clientId = clientId;
		this.saInfo = saInfo;
	}


	public void updateName(String name)
	{
		this.name = name;
	}
	
	public boolean isSameOne(String mcId,String pwd)
	{
		if(this.addrId.equals(mcId)
				&& this.pwd.equals(pwd))
		{
			return true;
		}
		return false;
	}

	public boolean isInvalid()
	{
		if(this.mcpttId == null
				|| this.mcpttId.length() <= 0
				|| this.mcvideoId == null
				|| this.mcvideoId.length() <= 0
				|| this.mcdataId == null
				|| this.mcdataId.length() <= 0
				|| this.clientId == null
				|| this.clientId.length() <= 0)
		{
			return true;
		}
		return false;
	}

	public UserInfo toUserInfo()
	{
		return new UserInfo(addrId,name,mcpttId,mcvideoId,mcdataId);
	}
	public AddrInfo toAddrInfo()
	{
		AddrInfo info = new AddrInfo(AddrInfo.UserType_User,name, addrId,AddrInfo.DEFAULT_ATTR);
		return info;
	}

	public String getAddrId()
	{
		return addrId;
	}
	public String getPwd()
	{
		return pwd;
	}
	public String getMcpttId() {
		return mcpttId;
	}

	public String getMcvideoId() {
		return mcvideoId;
	}

	public String getMcdataId() {
		return mcdataId;
	}
	public void updateAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public String getAccessToken() {
		return accessToken;
	}

	public String getClientId() {
		return clientId;
	}
	public String getName() {
		return name;
	}

	public void updateSaInfo(String saInfo) {
		this.saInfo = saInfo;
	}

	public String getSaInfo() {
		return saInfo;
	}

	public String getDscp()
	{

		if(name != null
				&& name.length() > 0)
		{
			return name;
		}
		if(addrId != null
				&& addrId.length() > 0)
		{
			return addrId;
		}
		else
		{
			return "";
		}
	}

	public int getPublishRsult() {
		return publishRsult;
	}

	public void setPublishRsult(int publishRsult) {
		this.publishRsult = publishRsult;
	}
	public String toString()
	{
		StringBuffer buffer = new StringBuffer("IdInfo:");
		buffer.append("name = ").append(name).append(",");
		buffer.append("addrId = ").append(addrId).append(",");
		buffer.append("pwd = ").append(pwd).append(",");

		buffer.append("mcpttId = ").append(mcpttId).append(",");
		buffer.append("mcvideoId = ").append(mcvideoId).append(",");
		buffer.append("mcdataId = ").append(mcdataId).append(",");

		buffer.append("accessToken = ").append(accessToken).append(",");

		buffer.append("saInfo = ").append(saInfo).append(",");
		buffer.append("clientId = ").append(clientId).append(";");

		return buffer.toString();
	}

	public static final Parcelable.Creator<McIdInfo> CREATOR = new Parcelable.Creator<McIdInfo>() {
		public McIdInfo createFromParcel(Parcel in) {
			return new McIdInfo(in);
		}

		public McIdInfo[] newArray(int size) {
			return new McIdInfo[size];
		}
	};

	private McIdInfo(Parcel in) 
	{
		addrId = getReadParcelableString(in.readString());
		pwd = getReadParcelableString(in.readString());
		mcpttId = getReadParcelableString(in.readString());
		mcvideoId = getReadParcelableString(in.readString());
		mcdataId = getReadParcelableString(in.readString());

		accessToken = getReadParcelableString(in.readString());
	}

	private String getWriteParcelableString(String str) {
		return (str == null) ? "null" : str;
	}
	private String getReadParcelableString(String str) {
		return str.equalsIgnoreCase("null") ? null : str;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(getWriteParcelableString(addrId));
		dest.writeString(getWriteParcelableString(pwd));
		dest.writeString(getWriteParcelableString(mcpttId));
		dest.writeString(getWriteParcelableString(mcvideoId));
		dest.writeString(getWriteParcelableString(mcdataId));

		dest.writeString(getWriteParcelableString(accessToken));
	}
}
